﻿using System;

namespace Tanmia.Basis.ViewModel
{
    [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    public sealed class ViewInfoAttribute : Attribute
    {
        public string Title
        {
            get { return ViewInfo.Title; }
        }

        public string Description
        {
            get { return ViewInfo.Description; }
        }

        public string ViewName
        {
            get { return ViewInfo.ViewName; }
        }

        public string RegionName
        {
            get { return ViewInfo.RegionName; }
        }

        internal ViewInfo ViewInfo { get; private set; }

        public ViewInfoAttribute(string title, string description)
            : this(title, description, string.Empty, string.Empty)
        {
        }

        public ViewInfoAttribute(string title, string regionName, string viewName)
            : this(title, string.Empty, regionName, viewName)
        {
        }

        public ViewInfoAttribute(string title, string description, string regionName, string viewName)
        {
            ViewInfo = new ViewInfo
            {
                Title = title,
                Description = description,
                RegionName = regionName,
                ViewName = viewName
            };
        }

        public static ViewInfoAttribute GetAttribute(Type type)
        {
            return GetCustomAttribute(type, typeof(ViewInfoAttribute)) as ViewInfoAttribute;
        }

        public static ViewInfo GetViewInfo(Type type)
        {
            return GetAttribute(type).ViewInfo;
        }
    }
}
